package cn.planewar;

import javax.swing.*;

public class Hero extends SkyObject {
    private int life;
    private int fire;
    public Hero(){
        super(97,139,151,461,3);
        life = 5;
        fire = 1;
    }
    public void step(){

    }
    public void loseLife(){
        if (life>0){
            life--;
        }
    }
    public void addFire(int i){
        if (fire<3) {
            fire += i;
        }
    }
    public void addLife(int i){
        life += i;
    }
    public int showFire(){
        return fire;
    }
    public int showLife(){
        return life;
    }
    public void clearFire() {
        fire = 1;
    }
    public void newGame(){
        clearFire();
        life = 5;
    }
    public boolean isHit(SkyObject other){
        int x_1 = other.getX()-(this.getWidth()-70);
        int x_2 = other.getX()+other.getWidth();
        int y_1 = other.getY()-(this.getHeight()-89);
        int y_2 = other.getY()+other.getHeight();
        int x_0 = this.getX()+35;
        int y_0 = this.getY();

        int x1 = other.getX()-this.getWidth();
        int x2 = other.getX()+other.getWidth();
        int y1 = other.getY()-(this.getHeight()-79);
        int y2 = other.getY()+other.getHeight();
        int x = this.getX();
        int y = this.getY()+50;

        return (x>=x1 && x<=x2 && y>=y1 && y<=y2)||(x_0>=x_1 && x_0<=x_2 && y_0>=y_1 && y_0<=y_2);
    }
    public ImageIcon getImage(){
        if (getObjstate()==0){
            return Image.hero0;
        } else {
            return Image.hero1;
        }
    }
}
